home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / stdio / gets.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  545b  |  38 lines

  1.  
  2. /*
  3.  *  GETS.C
  4.  *
  5.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  6.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  7.  *    DICE-LICENSE.TXT.
  8.  *
  9.  *  buf = gets(buf)
  10.  */
  11.  
  12. #include <stdio.h>
  13.  
  14. char *
  15. gets(buf)
  16. char *buf;
  17. {
  18.     int c;
  19.     int cnt = 0;
  20.     char *base = buf;
  21.  
  22.     while ((c = getc(stdin)) != EOF) {
  23.     *buf++ = c;
  24.     if (c != '\n' && cnt < BUFSIZ) {
  25.         ++cnt;
  26.         continue;
  27.     }
  28.     buf[-1] = 0;
  29.     return(base);
  30.     break;
  31.     }
  32.     if (buf == base)
  33.     return(NULL);
  34.     buf[0] = 0;
  35.     return(base);
  36. }
  37.  
  38.